﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using TomShane.Neoforce.Controls;
 
namespace SpaceInvade.Ships
 {
    public enum bulletType
    {
        Bullet1,
        Bullet2
    };

    public class Bullet
    {

        public Rectangle Location; //Position and size of the Bullet
        Vector2 speed = new Vector2(); //X and Y velocity
        public float DamageValue; //the amount of health that is taken away from a ship when the bullet collides with it
        bool IsDead; //if the bullet has hit something or has exited the screen, set to true to remove from list
        Ship srcShip; //the ship that fired the bullet
        Color bulletColor; //the color to fill the bullet with
        float baseDamage; //Base damage, initialized per bullet type;
        Vector2 baseSpeed;
        Vector2 ScreenEdge;
        int Rotation;

        public Bullet(Manager manager, bulletType btype, Vector4 PosAndSpeed, float percentModifier, Ship whoFired, int rotation)
        {
            Location.X = (int)PosAndSpeed.X;
            Location.Y = (int)PosAndSpeed.Y;
            ScreenEdge.X = manager.GraphicsDevice.Viewport.Bounds.Width;
            ScreenEdge.Y = manager.GraphicsDevice.Viewport.Bounds.Height;
            Rotation = rotation;
            switch (btype)
            {
                case bulletType.Bullet1:
                    Location.Width = 5;
                    Location.Height = 15;
                    baseDamage = 15f;
                    DamageValue = (int)(baseDamage * percentModifier);
                    baseSpeed.X = 20f;
                    baseSpeed.Y = 20f;
                    speed.X = (baseSpeed.X * PosAndSpeed.Z);
                    speed.Y = (baseSpeed.Y * PosAndSpeed.W);
                    bulletColor = Color.Green;
                    //BulletImage = img;
                    break;
                case bulletType.Bullet2:
                    Location.Width = 5;
                    Location.Height = 15;
                    baseDamage = 50f;
                    DamageValue = (int)(baseDamage * percentModifier);
                    baseSpeed.X = 20f;
                    baseSpeed.Y = 20f;
                    speed.X = (baseSpeed.X * PosAndSpeed.Z);
                    speed.Y = (baseSpeed.Y * PosAndSpeed.W);
                    bulletColor = Color.Red;
                    //BulletImage = img;
                    break;
            }
            srcShip = whoFired;
            DamageValue = 20.0f;
            IsDead = false;
        }
 

        public bool Update()
        {
            //move the bullet by the x and y velocities
            Location.X += (int)speed.X;
            Location.Y += (int)speed.Y;
            //Check if outside room (screen), if outside room then delete
            if (((Location.X - Location.Width) < 0 || Location.X > ScreenEdge.X) &&
                ((Location.Y - Location.Height) < 0 || Location.Y > ScreenEdge.Y))
                return true;
            else
                return false;
        }
 

        public void Draw(SpriteBatch spritebatch)
        {

            spritebatch.Draw(Game1.pixel, Location, bulletColor);
        }
         
        public Rectangle GetBoundingBox()
        {
            return Location;
        }

        //getters and setters of IsDead                 
        public bool GetIsDead()
        {
                return this.IsDead;
        }
        public void SetIsDead(bool isDead)
        {
                this.IsDead = isDead;
        }
                
    }
}